package cn.wen233.sunglow.controllers;

import cn.wen233.basic.http.RestResponse;
import cn.wen233.core.ServiceManager;
import cn.wen233.core.page.PageIn;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 命名空间 api
 *
 * @author wenei
 * @date 2021-10-18 13:56
 */
@RestController
@RequestMapping("/namespaces")
@RequiredArgsConstructor
public class NamespaceApi {

    private final ServiceManager serviceManager;

    @GetMapping
    public RestResponse<?> findAll() {
        return RestResponse.success(serviceManager.getAllNamespace());
    }

    @GetMapping("/{namespaceId}")
    public RestResponse<?> findByNamespaceId(@PathVariable String namespaceId) {
        return RestResponse.success(serviceManager.findNamespace(namespaceId));
    }

    @PostMapping
    public RestResponse<?> create(String namespaceId, String namespaceName, String description) {
        serviceManager.createNamespace(namespaceId, namespaceName, description);
        return RestResponse.success();
    }

    @PutMapping("/{namespaceId}")
    public RestResponse<?> update(@PathVariable String namespaceId, String namespaceName, String description) {
        serviceManager.updateNamespace(namespaceId, namespaceName, description);
        return RestResponse.success();
    }

    @DeleteMapping("/{namespaceId}")
    public RestResponse<?> delete(@PathVariable String namespaceId) {
        serviceManager.deleteNamespace(namespaceId);
        return RestResponse.success();
    }
}
